package com.gdufe.mistakebook.mapper;

import com.gdufe.mistakebook.entity.LabelQuestion;
import com.gdufe.mistakebook.entity.vo.count.LabelQuestionCountVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author hoshino
 */
@Mapper
public interface LabelQuestionMapper {

    /**
     * 根据错题ID查询标签ID列表
     *
     * @param id 错题ID
     * @return
     */
    @Select("select label_id from mistake_book.label_question where question_id = #{id} and status = 1")
    List<Integer> getLabelIdsByQuestionId(Integer id);

    /**
     * 插入标签与问题关系
     * @param labelQuestion
     */
    void insert(LabelQuestion labelQuestion);

    /**
     * 根据错题Id删除关系
     * @param questionId
     */
    @Delete("delete from label_question where question_id = #{questionId}")
    void delete(Integer questionId);

    @Select("select * from label_question where label_id = #{labelId} and status = 1")
    List<LabelQuestion> getLabelQuestionsByLabelId(Integer labelId);
    @Select("SELECT COUNT(DISTINCT label_question.question_id) AS count, label.label_name\n" +
            "FROM label_question\n" +
            "JOIN label ON label_question.label_id = label.id group by label_name;")
    List<LabelQuestionCountVO> selectLabelQuestionCount();
}




